<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i>后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item><a href="/user">用户管理</a></el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <div style="margin: 0 0 20px 0;">
<!--      <el-button type="primary" size="medium"-->
<!--                 @click="$router.push('/house/agent/add-new')">-->
<!--        添加经纪人-->
<!--      </el-button>-->
    </div>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="60" align="center"></el-table-column>
      <el-table-column prop="username" label="用户名" width="180" align="center"
                       show-overflow-tooltip></el-table-column>
      <el-table-column prop="nickname" label="昵称" align="center" width="100px"
                       show-overflow-tooltip></el-table-column>
      <el-table-column label="头像" align="center" width="100px">
        <template slot-scope="scope">
          <el-avatar :size="30" :src="scope.row.avatar"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column prop="phoneNumber" label="电话号码" align="center"
                       show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="email" label="邮箱" align="center"
                       show-overflow-tooltip></el-table-column>
      <el-table-column label="查看" width="100" align="center">
        <template slot-scope="scope">
          <el-button size="small" @click="agentDetails(scope.row)">查看</el-button>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" width="100" align="center">-->
<!--        <template slot-scope="scope">-->
<!--&lt;!&ndash;          <el-button size="mini" type="primary" icon="el-icon-edit" circle&ndash;&gt;-->
<!--&lt;!&ndash;                     @click="openEditDialog(scope.row)"></el-button>&ndash;&gt;-->
<!--          <el-button size="mini" type="danger" icon="el-icon-delete" circle-->
<!--                     @click="openDeleteConfirm(scope.row)"></el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <div style="text-align: right; margin: 10px auto;">
      <el-pagination
          @current-change="changePage"
          layout="total, prev, pager, next"
          :total="total"
          :current-page="currentPage"
          :page-size="pageSize">
      </el-pagination>
    </div>

    <el-dialog :visible.sync="dialogFormVisible2"  title="用户详情">
      <el-descriptions :model="details" column="1" border size="medium">
        <el-descriptions-item label="用户名" prop="username">{{details.username}}</el-descriptions-item>
        <el-descriptions-item label="密码" prop="password">{{details.password}}</el-descriptions-item>
        <el-descriptions-item label="头像" prop="avatar"><el-image
            style="width: 100px; height: 100px"
            :src="details.avatar"
            :fit="fit"></el-image></el-descriptions-item>
        <el-descriptions-item label="昵称" prop="nickname">{{details.nickname}}</el-descriptions-item>
        <el-descriptions-item label="电话" prop="phoneNumber">{{details.phoneNumber}}</el-descriptions-item>
        <el-descriptions-item label="邮箱" prop="email">{{details.email}}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>



  </div>
</template>

<script>
export default {
  data() {
    return {
      roleListOptions: [],
      tableData: [],
      total: 0,
      pageSize: 0,
      currentPage: 1,
      dialogFormVisible: false,
      dialogFormVisible2: false,
      details: {
        id:'',
        username: '',
        password:'',
        nickname:'',
        avatar:'',
        phoneNumber:'',
        email:'',
        entryTime: '',
      },
      editForm: {
        id:'',
        name: '',
        gender:'',
        age:'',
        idCard:'',
        phoneNumber:'',
        address:'',
        entryTime: '',
      },
      rules: {
        name: [
          {required: true, message: '请输入名称', trigger: 'blur'},
          {min: 2, max: 25, message: '长度在 2 到 25 个字符', trigger: 'blur'}
        ],
        description: [
          {required: true, message: '请输入简介', trigger: 'blur'}
        ],
        sort: [
          {required: true, message: '请输入排序序号', trigger: 'blur'},
          {pattern: /^(\d{1}|[1-9]{1}[0-9]?)$/,message: '排序序号必须是0~99之间的数字',trigger: 'blur'}
        ]
      },
    }
  },
  methods: {
    agentDetails(user) {
      let url = 'http://localhost:9200/user/standardById?id=' + user.id;
      this.axios.get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.dialogFormVisible2 = true;
          this.details = jsonResult.data
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    },
    changePage(value) {
      this.$router.replace('?page=' + value);
      this.loadUserList();

    },
    loadUserList() {
      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }

      let url = 'http://localhost:9200/user/list?page=' + page;




      this.axios.get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.total = jsonResult.data.total;
          this.pageSize = jsonResult.data.pageSize;
          this.currentPage = jsonResult.data.currentPage;
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    }
  },
  mounted() {
    this.loadUserList();
  }
}
</script>
